﻿@using A2.ERP.Models
@{
    List<p_ProductsStock_getDataSetByHouseDetailID_Result> ProductsStocklist = ViewBag.ProductsStock;
}
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>StockViewModule</title>
</head>
<body>
    <div id="StockViewModule">
        <div class="card">
            <div class="card-header">
                仓库库存情况
            </div>
            <div class="card-body">
                <div class="Stock-top" style="padding-top: 15px; padding-left: 15px;">
                    <div class="row">
                        <div class="col-sm">
                            <div class="input-group mb-3">
                                <div class="input-group-prepend">
                                    <label class="input-group-text" for="inputGroupSelect01">选择库房</label>
                                </div>
                                <select class="custom-select" id="t1" name="HouseID">
                                </select>
                            </div>
                        </div>
                        <div class="col-sm">
                            <div class="input-group mb-3">
                                <div class="input-group-prepend">
                                    <label class="input-group-text" for="inputGroupSelect01">选择库区</label>
                                </div>
                                <select class="custom-select" id="t2" name="HouseDetailID">
                                </select>
                            </div>
                        </div>
                        <div class="col-sm">
                            <input class="btn btn-primary btnSearch" type="submit" value="搜索">
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th>库房</th>
                    <th>库区</th>
                    <th>商品编号</th>
                    <th>商品名称</th>
                    <th>库存上限</th>
                    <th>库存下限</th>
                    <th>成本</th>
                    <th>现存量</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in ProductsStocklist)
                {
                    <tr>
                        <td>
                            @item.HouseName
                        </td>
                        <td>
                            @item.SubareaName
                        </td>

                        <td>
                            @item.ProductsID
                        </td>
                        <td>
                            @item.ProductsName
                        </td>
                        <td>
                            @item.UpperLimit
                        </td>
                        <td>
                            @item.LowerLimit
                        </td>
                        <td>
                            @item.Cost
                        </td>
                        <td>
                            @item.Num
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
    <script>
        $(function () {

            var $form = $('.form');

            var $btnSearch = $('.btnSearch');

            $.post('/Repertory/StroeHouseList', function (res) {
                $("#t1").empty();
                $.each(res, function (index, item) {
                    $("#t1").append('<option value="' + item.HouseID + '">' + item.HouseName + '</option>');
                })
            })

            $.post('/Repertory/StroeHouseListData', { id: 1 }, function (res) {
                $("#t2").empty();
                if (res.length > 0) {
                    $.each(res, function (index, item) {
                        $("#t2").append('<option value="' + item.ID + '">' + item.SubareaName + '</option>');
                    })
                } else {
                    $("#t2").append('<option>暂无数据</option>');
                }
            })


            $("#t1").on('change', function () {
                $.post('/Repertory/StroeHouseListData', { id: $("#t1").val() }, function (res) {
                    $("#t2").empty();
                    if (res.length > 0) {
                        $.each(res, function (index, item) {
                            $("#t2").append('<option value="' + item.ID + '">' + item.SubareaName + '</option>');
                        })
                    } else {
                        $("#t2").append('<option>暂无数据</option>');
                    }
                })
            });

            $btnSearch.on('click', function (e) {
                console.log($('#t2').val());
                //return;
                $tab.reloadTab('#StockViewModule', [{ HouseID: $('#t1').val() }, { HouseDetailID: $('#t2').val() }]);
            });

        });
    </script>
</body>
</html>
